﻿using System.Data;
using System.Text;
using BO.Infrastructure.StaticData;
using BO.Infrastructure.Utils;

namespace GUI.Controls.Sport
{
    public partial class HighlightNewsInCategory : System.Web.UI.UserControl
    {
        private const string TopItemFormat = @"{4}<h2><a title=""{0}"" href=""{3}"">{1}{5}</a></h2><p>{2}</p>";
        private const string LiFormat = @"<li>{3}<h2><a title=""{0}"" href=""{2}"">{1}{4}</a></h2></li>";
        private const int ImageWidth1 = 400;
        private const int ImageHeight1 = 300;
        private const int ImageWidth2 = 110;
        private const int ImageHeight2 = 83;




        internal bool DataBind(DataTable dtTopItem, DataTable dtOtherItem)
        {
            if (dtTopItem != null && dtTopItem.Rows.Count > 0)
            {
                var r = dtTopItem.Rows[0];

                var avatar = PresentationUtils.Photo.BuildNewsAvatar(r, ImageWidth1, ImageHeight1, lazyLoad: true);

                ltrTop.Text = string.Format(TopItemFormat,
                                            r[SqlConstants.NewsPublish.EncodedTitle],
                                            r[SqlConstants.NewsPublish.Title],
                                            r[SqlConstants.NewsPublish.InitSapo],
                                            r[SqlConstants.NewsPublish.Url],
                                            avatar,
                                            r[SqlConstants.NewsPublish.NewsTypeIcon]
                    );
            }
            if (dtOtherItem != null && dtOtherItem.Rows.Count > 0)
            {
                var sb = new StringBuilder();

                foreach(DataRow r in dtOtherItem.Rows)
                {
                    var avatar = PresentationUtils.Photo.BuildNewsAvatar(r, ImageWidth2, ImageHeight2, lazyLoad: true);

                    sb.Append(string.Format(LiFormat,
                                            r[SqlConstants.NewsPublish.EncodedTitle],
                                            r[SqlConstants.NewsPublish.Title],
                                            r[SqlConstants.NewsPublish.Url],
                                            avatar,
                                            r[SqlConstants.NewsPublish.NewsTypeIcon]
                                  ));
                }
                ltrList.Text = sb.ToString();
            }
            return true;
        }

    }
}

